home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #26 (Nov 87) / Pascal Code Tester / CodeTesterStuff < prev    next >
Text File  |  1987-10-26  |  7KB  |  303 lines

  1. PROGRAM CodeTester;
  2.  
  3. (* Version 1.1 *)
  4. (* © CopyRight 1987 by J.E.Fox, for Mactutor™ *)
  5.  
  6. {I-}
  7.  
  8.     USES
  9.         ROM85, TestGlobals, TestStuff;
  10.  
  11.     PROCEDURE crash;
  12.     BEGIN
  13.         ExitToShell;
  14.     END;
  15.  
  16.     PROCEDURE DoAbout;
  17.         VAR
  18.             MyAbout : DialogPtr;
  19.             ItemHit : Integer;
  20.     BEGIN
  21.         MyAbout := GetNewDialog(AboutId, NIL, Pointer(-1));
  22.         ShowWindow(MyAbout);
  23.         ModalDialog(NIL, ItemHit);
  24.         CASE ItemHit OF
  25.             1 : 
  26.                 DisposDialog(MyAbout);
  27.             OTHERWISE
  28.                 BEGIN
  29.                 END;
  30.         END;  (* Case of *)
  31.     END;  (* DoAbout *)
  32.  
  33.     PROCEDURE ProcessMenu_in (CodeWord : longint);
  34.         VAR
  35.             Menu_No : integer;        {menu number that was selected}
  36.             Item_No : integer;        {item in menu that was selected}
  37.             Name : Str255;               {name holder for desk accessory or font}
  38.             OpenDAResult : integer;
  39.             TempPort : Grafptr;    {protect against DA}
  40.     BEGIN
  41.         IF CodeWord <> 0 THEN
  42.             BEGIN {go ahead and process the command}
  43.                 Menu_No := HiWord(CodeWord);   {get the Hi word of...}
  44.                 Item_no := LoWord(CodeWord);   {get the Lo word of...}
  45.                 CASE Menu_No OF
  46.                     AppleMenu : 
  47.                         BEGIN
  48.                             CASE Item_No OF
  49.                                 1 : 
  50.                                     DoAbout;
  51.                                 OTHERWISE
  52.                                     BEGIN
  53.                                         GetItem(AppleMHandle, Item_No, Name);
  54.                                         GetPort(TempPort);
  55.                                         OpenDAResult := OpenDeskAcc(Name);
  56.                                         SetPort(TempPort);
  57.                                     END;     (* Otherwise *)
  58.                             END         (* Case Item_No of *)
  59.                         END;          (* Case Menu_No of *)
  60.                     FileMenu : 
  61.                         BEGIN
  62.                             CASE Item_No OF
  63.                                 1 : 
  64.                                     theTest;
  65.                                 2 : 
  66.                                     BEGIN
  67.                     (* The dividing Line *)
  68.                                     END;
  69.                                 3 : 
  70.                                     BEGIN
  71.                                         SetCursor(Watch);
  72.                                         Finished := True;          (* quit *)
  73.                                     END;
  74.                             END;    (* Item_No of (File) *)
  75.                         END;    (* Menu_No of (File) *)
  76.                 END; (* Case Menu_No of *)
  77.                 HiliteMenu(0);               (* unhilite after processing menu *)
  78.             END; (* the If codeword <>0 *)
  79.     END; (* of ProcessMenu_in procedure *)
  80.  
  81.     PROCEDURE DealwthMouseDowns (Event : EventRecord);
  82.         VAR
  83.             WindowPointedTo : WindowPtr;
  84.             GlobalMouse, LocalMouse : Point;
  85.             WindoLoc : integer;
  86.             TempPort : GrafPtr;
  87.     BEGIN
  88.         GlobalMouse := Event.Where;
  89.         LocalMouse := GlobalMouse;
  90.         GlobalToLocal(LocalMouse);
  91.         WindoLoc := FindWindow(GlobalMouse, WindowPointedTo);
  92.         CASE WindoLoc OF
  93.             inMenuBar : 
  94.                 ProcessMenu_in(MenuSelect(GlobalMouse));
  95.             inSysWindow : 
  96.                 SystemClick(Event, WindowPointedTo);
  97.             inContent : 
  98.                 BEGIN
  99.                     IF WindowPointedTo <> FrontWindow THEN
  100.                         BEGIN
  101.                             SelectWindow(WindowPointedTo);
  102.                             SetPort(WindowPointedTo);
  103.                         END;
  104.                 END;    {InContent}
  105.             inGrow : 
  106.                 BEGIN
  107.                 END;
  108.             inDrag : 
  109.                 BEGIN
  110.                     DragWindow(WindowPointedTo, GlobalMouse, DragArea);
  111.                 END;
  112.             inGoAway : 
  113.                 BEGIN
  114.                     IF TrackGoAway(WindowPointedTo, GlobalMouse) THEN
  115.                         HideWindow(WindowPointedTo);
  116.                 END;
  117.             InZoomIn, InZoomOut : 
  118.                 BEGIN
  119.                     IF TrackBox(WindowPointedTo, GlobalMouse, WindoLoc) THEN
  120.                         BEGIN
  121.                             GetPort(TempPort);
  122.                             SetPort(WindowPointedTo);
  123.                             EraseRect(WindowPointedTo^.portRect);
  124.                             ZoomWindow(WindowPointedTo, WindoLoc, True);
  125.                             SetPort(TempPort);
  126.                         END;
  127.                 END;
  128.             OTHERWISE
  129.                 BEGIN
  130.                 END;
  131.         END;       (* CASE WindoLoc of *)
  132.     END;    (* DealwthMouseDowns *)
  133.  
  134.     PROCEDURE DealwthKeyDowns (Event : EventRecord);
  135.         VAR
  136.             CharCode : char;
  137.     BEGIN
  138.         CharCode := Chr(Event.message MOD 256);
  139.         IF BitAnd(Event.modifiers, CmdKey) = CmdKey THEN
  140.             ProcessMenu_in(MenuKey(CharCode));
  141.     END;
  142.  
  143.     PROCEDURE Activate_DeActivate (Event : EventRecord);
  144.         VAR
  145.             TargetWindow : WindowPtr;
  146.     BEGIN
  147.         TargetWindow := WindowPtr(Event.message);
  148.         IF Odd(Event.modifiers) THEN
  149.             BEGIN    (* then the window is becoming active *)
  150.                 SetPort(TargetWindow);
  151.                 TEActivate(JeffsText);
  152.             END  (* If Odd *)
  153.         ELSE
  154.             BEGIN
  155.                 TEDeactivate(JeffsText);
  156.             END;  (* Deactivate *)
  157.     END;  (* Activate_DeActivate *)
  158.  
  159.     PROCEDURE DealwthUpdates (Event : EventRecord);
  160.         VAR
  161.             UpDateWindow, TempPort : WindowPtr;
  162.     BEGIN
  163.         UpDateWindow := WindowPtr(Event.message);
  164.         GetPort(TempPort);
  165.         SetPort(UpDateWindow);
  166.         BeginUpDate(UpDateWindow);
  167.         EraseRect(UpDateWindow^.portRect);
  168.         MoveHHi(handle(JeffsText));
  169.         HLock(handle(JeffsText));
  170.         TEUpdate(UpdateWindow^.portRect, JeffsText);
  171.         theDrawing;
  172.         HUnlock(handle(JeffsText));
  173.         EndUpDate(UpDateWindow);
  174.         SetPort(TempPort);
  175.     END;
  176.  
  177.     PROCEDURE MainEventLoop;
  178.         VAR
  179.             Event : EventRecord;
  180.     BEGIN
  181.         REPEAT
  182.             SystemTask;
  183.             TEIdle(JeffsText);
  184.             IF GetNextEvent(EveryEvent, Event) THEN
  185.                 CASE Event.what OF
  186.                     mouseDown : 
  187.                         DealwthMouseDowns(Event);
  188.                     KeyDown, AutoKey : 
  189.                         DealwthKeyDowns(Event);
  190.                     ActivateEvt : 
  191.                         Activate_DeActivate(Event);
  192.                     UpDateEvt : 
  193.                         DealwthUpdates(Event);
  194.                     OTHERWISE
  195.                         BEGIN
  196.                         END;
  197.                 END;(* of Case *)
  198.         UNTIL Finished;
  199.     END;
  200.  
  201.     PROCEDURE PrimeMemory;
  202.     BEGIN
  203. {    MaxApplZone;  Grow Heap to Limit }
  204.         MoreMasters;                      (* Allot 5, 64 Mptr Blocks *)
  205.         MoreMasters;
  206.         MoreMasters;
  207.         MoreMasters;
  208.         MoreMasters;
  209.     END;
  210.  
  211.     PROCEDURE Close;
  212.     BEGIN
  213.     END;
  214.  
  215. (* ŸŸŸ      Following are called by Set Up       ŸŸŸŸŸ *)
  216.  
  217.     PROCEDURE Energize;
  218.         VAR
  219.             BeamH, WatchH : CursHandle;
  220.     BEGIN
  221.         InitGraf(@thePort);     (* Set up all Managers *)
  222.         InitFonts;
  223.         InitWindows;
  224.         InitMenus;
  225.         TEInit;
  226.         InitDialogs(@crash);    (* crash is Proc to 'Resume' in Bomb DLOG *)
  227.         InitAllPacks;
  228.         FlushEvents(everyEvent, 0);
  229.  
  230.         WatchH := GetCursor(watchCursor);    (* Put watchs Mptr address on stack *)
  231.         HLock(Handle(WatchH));        (* Just in case, Note the type clash *)
  232.         Watch := WatchH^^;            (* DDeref and store, easier to call *)
  233.         SetCursor(Watch);            (* Wrap 10 Mr. Sulu *)
  234.         Finished := False;                    (* program terminator *)
  235.     END;
  236.  
  237.     PROCEDURE SetupMenus;
  238.  
  239.     BEGIN
  240.         AppleMHandle := GetMenu(AppleMenu);
  241.         InsertMenu(AppleMHandle, 0);
  242.         FileMHandle := GetMenu(FileMenu);
  243.         InsertMenu(FileMHandle, 0);
  244.         AddResMenu(AppleMHandle, 'DRVR');
  245.         MoveHHI(Handle(AppleMHandle));
  246.         HLock(Handle(AppleMHandle));        (* since this could be dumped *)
  247.         MoveHHI(handle(FileMHandle));
  248.         HLock(Handle(FileMHandle));
  249.  
  250.         DrawMenuBar;
  251.     END;
  252.  
  253.     PROCEDURE SetupLimits;
  254.     BEGIN
  255.         Screen := ScreenBits.Bounds;   {set the size of the screen}
  256.         SetRect(DragArea, Screen.left + 4, Screen.top + 24, Screen.right - 4, Screen.bottom - 4);
  257.         SetRect(GrowArea, Screen.left, Screen.top + 24, Screen.right, Screen.bottom);
  258.         SetRect(WindowArea, Screen.left + 10, Screen.Top + 40, Screen.right - 200, Screen.bottom - 200);
  259.     END;
  260.  
  261.     PROCEDURE SetUpWindow;
  262.         VAR
  263.             title : str255;
  264.     BEGIN
  265.         title := 'Code Tester';
  266.         JeffsWindow := NewWindow(NIL, WindowArea, title, FALSE, 8, pointer(-1), TRUE, 1);
  267.         IF JeffsWindow = NIL THEN
  268.             crash;
  269.         SetPort(JeffsWindow);
  270.         TextFont(applFont);
  271.         TextSize(12);
  272.         TextFace([]);
  273.         TextMode(1);
  274.     END;
  275.  
  276.     PROCEDURE SetUpTE;
  277.     BEGIN
  278.         WITH JeffsWindow^.portRect DO
  279.             BEGIN
  280.                 SetRect(ViewArea, left + 4, top + 4, right - 1, bottom - 1);
  281.             END;
  282.         DestArea := ViewArea;
  283.         JeffsText := TENew(DestArea, ViewArea); { must be done after setPort}
  284.     END;
  285.  
  286.     PROCEDURE MainSetUp;
  287.     BEGIN
  288.         Energize;
  289.         SetupMenus;
  290.         SetupLimits;
  291.         SetUpWindow;        (* Save Room for the windows if used *)
  292.         SetUpTE;
  293.         InitCursor;          (* ready to go, so show the Arrow cursor *)
  294.     END;
  295.  
  296. (* ŸŸŸŸŸŸŸ Main Program ŸŸŸŸŸŸŸ *)
  297.  
  298. BEGIN
  299. {PrimeMemory;}
  300.     MainSetUp;
  301.     MainEventLoop;
  302.     Close;
  303. END.